<?php 

session_start();

$alcool = $_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]];

if(isset($_POST["modifier"])){

	$alc["nom"] = $_REQUEST["nomInput"];
	$alc["type"] = $_REQUEST["typeInput"];
	$alc["provenance"] = $_REQUEST["provenanceInput"];
	$alc["annee"] = $_REQUEST["anneeInput"];
	$alc["tauxAlcool"] = $_REQUEST["alcoolInput"];
	$alc["qty"] = $_REQUEST["bouteillesInput"];
	$alc["favoris"] = @$_REQUEST["favoriInput"] == "oui" ? true : false;
	$alc["cote"] = $_REQUEST["coteInput"];
	$alc["description"] = $_REQUEST["descriptionInput"];
	$alc["notes"] = $_REQUEST["noteInput"];
	$alc["image"] = basename( $_FILES["photoInput"]["name"]);
	$alc["rabais"] = false;
	if($alc["image"] == ""){
		$alc["image"] = @$alcool["image"];
	}


	$temp = explode($_SERVER['SCRIPT_FILENAME'], "/");
	$imagePath = "";
	for ($i=0;$i<count($temp)-1;$i++)
	{
		$imagePath = $imagePath . $temp[$i] . "/";
	}
	$imagePath = $imagePath . "images/";

	$target_path = $imagePath;

	$target_path = $target_path . $alc["image"];

	if(move_uploaded_file($_FILES['photoInput']['tmp_name'], $target_path)) {
		//echo "Le fichier ".  basename( $_FILES['photoInput']['name']).
		//" a �t� charg� avec succ�s";
	} else{
		//echo "Une erreur s'est produite. Veuillez réessayer!";
	}


	$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]] = $alc;

	header("Location: alcool.php?iid=".$_REQUEST["iid"]."&aid=".$_REQUEST["aid"]);
}

$alcool = $_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]];


@include 'include/header.php';
?>
<div id="contenu">
	<h1>Modifier un alcool</h1>
	<form id="alcoolForm" action="modifierAlcool.php"
		enctype="multipart/form-data" method="post">

		<input type="hidden" name="iid"
			value="<?php echo $_REQUEST["iid"]; ?>"> <input type="hidden"
			name="aid" value="<?php echo $_REQUEST["aid"]; ?>">

		<div class="infos">
			<div class="photo">
			
				<?php 
				echo " 
					<p><img src=\"images/".$alcool["image"]."\" alt=\"Photo\" /></p>";
				?>
				<p>
					<label for="photoInput">changer la photo:</label>
				</p>
				<p>
					<input type="file" id="photoInput" name="photoInput" />
				</p>
			</div>
			<div class="infosGenerales">
				<div class="ligne">
					<label for="nomInput">Nom:</label><input type="text" id="nomInput"
						name="nomInput" value="<?php echo $alcool["nom"]; ?>" />
				</div>
				<div class="ligne">
					<label for="typeInput">Type:</label> <select id="typeInput"
						name="typeInput">
						<option <?php if ($alcool["type"] == "Bière"){echo "selected";} ?>
							value="Bière">Bière</option>
						<option
						<?php if ($alcool["type"] == "Spiritueux"){echo "selected";} ?>
							value="Spiritueux">Spiritueux</option>
						<option
						<?php if ($alcool["type"] == "Vin blanc"){echo "selected";} ?>
							value="Vin blanc">Vin blanc</option>
						<option
						<?php if ($alcool["type"] == "Vin rouge"){echo "selected";} ?>
							value="Vin rouge">Vin rouge</option>
					</select>
				</div>
				<div class="ligne">
					<label for="anneeInput">Millésime:</label><input type="text"
						id="anneeInput" name="anneeInput"
						value="<?php echo $alcool["annee"]; ?>" />
				</div>
				<div class="ligne">
					<label for="provenanceInput">Provenance:</label><input type="text"
						id="provenanceInput" name="provenanceInput"
						value="<?php echo $alcool["provenance"]; ?>" />
				</div>
				<div class="ligne">
					<label for="alcoolInput">% d'alcool:</label><input type="text"
						id="alcoolInput" name="alcoolInput"
						value="<?php echo $alcool["tauxAlcool"]; ?>" />
				</div>
				<div class="ligne">
					<label for="bouteillesInput">Nombre de bouteilles:</label><input
						type="text" id="bouteillesInput" name="bouteillesInput"
						value="<?php echo $alcool["qty"]; ?>" />
				</div>
				<div class="ligne">
					<label for="favoriInput">Favori:</label><input type="checkbox"
						id="favoriInput" name="favoriInput"
						<?php if ($alcool["favoris"]){echo "checked";} ?> value="oui" />
				</div>
				<div class="ligne">
					<label for="coteInput">Cote:</label> <select id="coteInput"
						name="coteInput">
						<option <?php if ($alcool["cote"] == "0"){echo "selected";} ?>
							value="0">0</option>
						<option <?php if ($alcool["cote"] == "1"){echo "selected";} ?>
							value="1">1</option>
						<option <?php if ($alcool["cote"] == "2"){echo "selected";} ?>
							value="2">2</option>
						<option <?php if ($alcool["cote"] == "3"){echo "selected";} ?>
							value="3">3</option>
						<option <?php if ($alcool["cote"] == "4"){echo "selected";} ?>
							value="4">4</option>
						<option <?php if ($alcool["cote"] == "5"){echo "selected";} ?>
							value="5">5</option>
					</select>
				</div>

			</div>
		</div>
		<div class="description">
			<h2>
				<label for="descriptionInput">Description</label>
			</h2>
			<textarea rows="5" cols="80" id="descriptionInput"
				name="descriptionInput">
				<?php echo $alcool["description"]; ?>
			</textarea>
		</div>
		<div class="note">
			<h2>
				<label for="noteInput">Note de dégustation</a>
			
			</h2>
			<textarea rows="5" cols="80" id="noteInput" name="noteInput">
				<?php echo $alcool["notes"]; ?>
			</textarea>
		</div>
		<input type="submit" value="Modifier" name="modifier" id="modifier" />
	</form>
</div>
</body>

</html>
